/*
* Code: Dzlua
* QQ  : 505544956
* Time: 2017/05/23
*/
#ifndef _DZLUA_BASE_H_
#define _DZLUA_BASE_H_
#pragma once

#include "../export.h"

namespace dzlua {

namespace base {

/*
note:
    execute a shell cmd,if execute return true,else return false.
    Warning: if it return true not represent the cmd return true.
example:
    std::string cmd = "echo";//cmd = "c://test.exe";
    std::string args = "Hellow Dzlua.";
    bool executed = dzlua::base::ExecuteShell(cmd, args);
*/
DZLUA_BASE_EXPORT bool ExecuteShell(const std::string& cmd, const std::string& args, bool wait = false);
DZLUA_BASE_EXPORT bool ExecuteShell(const std::wstring& cmd, const std::wstring& args, bool wait = false);

/*
    place the give str at begin and end of src 
    src:"aaa",str:"."->".aaa."
*/
DZLUA_BASE_EXPORT std::string AroundMarks(const std::string& str, const std::string& mark);
DZLUA_BASE_EXPORT std::wstring AroundMarks(const std::wstring& str, const std::wstring& mark);

/*
    " abcdefg "->"abcdefg";
*/
DZLUA_BASE_EXPORT std::string trim(const std::string& src);
DZLUA_BASE_EXPORT std::wstring trim(const std::wstring& src);

/*
    ("abcdefghijk","def","mmm")->"abcmmmghijk";
*/
DZLUA_BASE_EXPORT std::string replace(const std::string& src, const std::string& strold, const std::string& strnew);
DZLUA_BASE_EXPORT std::wstring replace(const std::wstring& src, const std::wstring& strold, const std::wstring& strnew);

/*
    ("www.baidu.com",".",&v)->
        v: v[0]->"www"
            v[1]->"baidu"
            v[2]->"com"
*/
DZLUA_BASE_EXPORT void split(const std::string& src, const std::string& delim, std::vector<std::string>* ret);
DZLUA_BASE_EXPORT void split(const std::wstring& src, const std::wstring& delim, std::vector<std::wstring>* ret);

/*
    v: v[0]->"www"
        v[1]->"baidu"
        v[2]->"com"
    unsplit(v, '.');-> "www.baidu.com"
*/
DZLUA_BASE_EXPORT std::string unsplit(const std::vector<std::string>& v, const std::string& delim);
DZLUA_BASE_EXPORT std::wstring unsplit(const std::vector<std::wstring>& v, const std::wstring& delim);

/*
    "aBcDeFg"->"abcdefg"
*/
DZLUA_BASE_EXPORT std::string lower(const std::string& str);
DZLUA_BASE_EXPORT std::wstring lower(const std::wstring& str);

/*
    "aBcDeFg"->"ABCDEFG"
*/
DZLUA_BASE_EXPORT std::string upper(const std::string& str);
DZLUA_BASE_EXPORT std::wstring upper(const std::wstring& str);

/*
      format('hello %s, 1 + 1 = %d', 'dzlua', 2);
    -> 'hello dzlua, 1 + 1 = 2'
*/
DZLUA_BASE_EXPORT std::string format(const char* fmt, ...);
DZLUA_BASE_EXPORT std::wstring format(const wchar_t* fmt, ...);

/*
    ?
*/
DZLUA_BASE_EXPORT bool IsAlphaNum(const std::string& str, int type);
DZLUA_BASE_EXPORT bool IsAlphaNum(const std::wstring& str, int type);

/*
*/
DZLUA_BASE_EXPORT void Base64Encode(const std::string& input, std::string* output);
DZLUA_BASE_EXPORT bool Base64Decode(const std::string& input, std::string* output);

/*
    Convert
*/
DZLUA_BASE_EXPORT std::string  WToA(const std::wstring& str);
DZLUA_BASE_EXPORT std::wstring AToW(const std::string& str);
DZLUA_BASE_EXPORT std::wstring UToW(const std::string& str);
DZLUA_BASE_EXPORT std::string  WToU(const std::wstring& str);
DZLUA_BASE_EXPORT std::string  AToU(const std::string& str);
DZLUA_BASE_EXPORT std::string  UToA(const std::string& str);

} // end namespace base

} //end namespace dzlua

#endif //_DZLUA_BASE_H_